import { defineComponent, reactive, ref } from "vue";
import Page from "@/components/public/page/page";
import { CardWithTitle } from "@/components/public/card/card";
import LTable from "@/components/public/lTable/lTable";
import channelUsersService from "@/modules/channelManagement/channelUsersPage/channelUsers.service";
import { CircleStateTitle } from "@/components/public/dotStateTitle/dotStateTitle";
import useNavigator from "@/hooks/useNavigator";
export default defineComponent({
  name: 'channelUsersPage',
  setup() {
    const navigator = useNavigator();
    const state = reactive({
      toolbar: {
        left: ["refresh",],
        right: ["filter", "search"],
      },
      dataSource: [],
      columns: [
        {
          title: "Id",
          dataIndex: "id",
          key: "id",
          align: "center",
          width: "50px",
        },
        {
          title: "用户名",
          dataIndex: "username",
          align: "center",
          width: "200px",
        },
        {
          title: "手机号",
          dataIndex: "mobile",
          align: "center",
          width: "100px",
        },
        {
          title: "机构名称",
          dataIndex: "agency_name",
          align: "center",
          width: "200px",
        },
        {
          title: "余额",
          dataIndex: "balance",
          align: "center",
          width: "180px",
        },
        {
          title: "是否认证",
          dataIndex: "is_auth",
          align: "center",
          width: "100px",
        },
        {
          fixed: "right",
          title: "操作",
          dataIndex: "operation",
          align: "center",
          width: "100px",
        },
      ],
      loading: false,
      searchForm: {
        agency_name: {
          type: "input",
          label: "机构名称",
          attrs: { placeholder: "请输入机构名称" },
        },
      },
      pagination: {
        total: 0,
        current: 1,
        pageSize: 10,
      },
    } as any);
    const LTableRef = ref(null as any);
    const $service = new channelUsersService();

    //折扣设置
    const toDiscount = (record: any) => {
      navigator.push({ name: "discountSetPage", query: { id: record.id } })
    }

    // 表格状态变更
    const tableChangeHandler = (pag: { pageSize: number; current: number }) => {
      state.pagination.current = pag.current;
      state.pagination.pageSize = pag.pageSize;
    };

    return () => (
      <Page>
        <CardWithTitle title="渠道账户">
          <LTable
            ref={LTableRef}
            toolbar={state.toolbar}
            service={$service}
            v-model={state}
          >
            <a-table
              bordered={true}
              scroll={{ x: "max-content" }}
              dataSource={state.dataSource}
              columns={state.columns}
              pagination={state.pagination}
              loading={state.loading}
              onChange={tableChangeHandler}
              v-slots={{
                bodyCell: ({ column, record }: any) => {
                  //操作
                  if (column.dataIndex === "operation") {
                    return (
                      <div class="operation">
                        <a-button type="primary" onClick={() => { toDiscount(record) }}>折扣配置</a-button>
                        {/* <a-button type="primary" onClick={() => { toRecharge(record) }}>去充值</a-button> */}
                      </div>
                    )
                  }
                  //审核状态
                  if (column.dataIndex === "is_auth") {
                    return (
                      record.is_auth ? <CircleStateTitle title="已认证" type="success" /> : <CircleStateTitle title="未认证" type="warning" />
                    )
                  }
                },
              }}
            />
          </LTable>
        </CardWithTitle>
      </Page>
    )
  }
})